$(function(){
	var admin_id = getCookie('admin_id');
	if(!admin_id){
		window.location.replace('login.html');
	}
	$.ajax({
		url: ApiUrl + "/shopping?limit="+Page,
        type: 'get',
        dataType: 'JSON',
        success: function(result) {
        	if(result.code == 200){
        		var pageCount = result.data.totalPage;
        		//生成分页按钮
				if(pageCount>5){
					page_icon(1,5,0,pageCount);
				}else{
					page_icon(1,pageCount,0,pageCount);
				}
        	}else{
	    		parent.layer.msg(result.message);
	    		return false;
	    	}
        }
    });
	list_value();
});
function list_value(page){
	if(!page){
		//获取店员列表
	    $.ajax({
			url: ApiUrl + "/shopping?limit="+Page,
	        type: 'get',
	        dataType: 'JSON',
	        success: function(result) {
	        	if(result.code == 200){
	        		var html='';
	        		$.each(result.data.list, function(k, v) {
	        			html+='<tr>'
	                            +'<td>'+v.id+'</td>'
	                            +'<td>'+v.out_trade_no+'</td>'
	                            +'<td>'+v.username+'</td>'
	                            +'<td>'+v.trade_no+'</td>'
	                            +'<td>'+v.total_amount+'</td>';
	                    if(v.pay_type == 1){
	                    	html+= '<td>人民币</td>';
	                    }else if(v.pay_type == 2){
	                    	html+= '<td>银行卡</td>';
	                    }else if(v.pay_type == 3){
	                    	html+= '<td>积分兑换</td>';
	                    }else if(v.pay_type == 4){
	                    	html+= '<td>微信</td>';
	                    }else if(v.pay_type == 5){
	                    	html+= '<td>支付宝</td>';
	                    }else if(v.pay_type == 6){
	                    	html+= '<td>会员卡</td>';
	                    }else if(v.pay_type == 7){
	                    	html+= '<td>礼券</td>';
	                    }
	                    if(v.pay_status == 1){
	                    	html+= '<td>成功</td>';
	                    }else{
	                    	html+= '<td>失败</td>';
	                    }
	                        html+='<td>'+v.total_amount+'</td>'
	                            +'<td>'+v.auth_code+'</td>'
	                            +'<td>'+v.created_at+'</td>'
	                            +'<td><a title = "购物详情"  href="shopping_detail.html?id='+v.id+'" class="btn btn-primary btn-circle"><i class="fa fa-list"></i></a>';
                      
	        		});
	        		$("#value").html(html);
	        	}else{
		    		parent.layer.msg(result.message);
		    		return false;
		    	}
	        }
	    });
	}else{
		//$("#value").empty();
		//获取店员列表
	    $.ajax({
			url: ApiUrl + "/shopping?limit="+Page+"&page="+page,
	        type: 'get',
	        dataType: 'JSON',
	        success: function(result) {
	        	if(result.code == 200){
	        		var html='';
	        		$.each(result.data.list, function(k, v) {
	        			html+='<tr>'
	                            +'<td>'+v.id+'</td>'
	                            +'<td>'+v.out_trade_no+'</td>'
	                            +'<td>'+v.username+'</td>'
	                            +'<td>'+v.trade_no+'</td>'
	                            +'<td>'+v.total_amount+'</td>';
	                    if(v.pay_type == 1){
	                    	html+= '<td>人民币</td>';
	                    }else if(v.pay_type == 2){
	                    	html+= '<td>银行卡</td>';
	                    }else if(v.pay_type == 3){
	                    	html+= '<td>积分兑换</td>';
	                    }else if(v.pay_type == 4){
	                    	html+= '<td>微信</td>';
	                    }else if(v.pay_type == 5){
	                    	html+= '<td>支付宝</td>';
	                    }else if(v.pay_type == 6){
	                    	html+= '<td>会员卡</td>';
	                    }else if(v.pay_type == 7){
	                    	html+= '<td>礼券</td>';
	                    }
	                    if(v.pay_status == 1){
	                    	html+= '<td>成功</td>';
	                    }else{
	                    	html+= '<td>失败</td>';
	                    }
	                        html+='<td>'+v.total_amount+'</td>'
	                            +'<td>'+v.auth_code+'</td>'
	                            +'<td>'+v.created_at+'</td>'
	                            +'<td><a title = "购物详情"  href="shopping_detail.html?id='+v.id+'" class="btn btn-primary btn-circle"><i class="fa fa-list"></i></a>';
                      
	        		});
	        		$("#value").html(html);
	        	}else{
		    		parent.layer.msg(result.message);
		    		return false;
		    	}
	        }
	    });
	}
	
}
function updatastatus(id,status){
	$.ajax({
		url: ApiUrl + "/goods/status/"+id,
        type: 'post',
        data:{
        	status :status
        },
        dataType: 'JSON',
        success: function(result) {
        	if(result.code == 200){
        		$(".alert").text('操作成功，页面即将自动跳转~');
	  			$(".alert").addClass('block').fadeIn(200);
	  			$(".alert").removeClass('alert-danger alert-warning alert-info alert-success').addClass('alert-success');
	  			setTimeout(function(){
	  					location.reload();
				},3000);
        	}else{
        		$(".alert").text(data.message);
	  			$(".alert").addClass('block').fadeIn(200);
	  			$(".alert").removeClass('alert-danger alert-warning alert-info alert-success').addClass('alert-danger');
	  			setTimeout(function(){
					$(".alert").removeClass('block');
					$("#alert").css('display','none'); 
				},3000);
        	}
    	}
    })
}
